<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 使字符串平衡的最少删除次数 -->
    <script>
      var minimumDeletions = function (s) {
        // 动态规划 非常非常巧妙
        let f = 0
        let cnt = 0
        for (let i = 0; i < s.length; i++) {
          if (s[i] == 'b') cnt++
          else {
            f = Math.min(f + 1, cnt)
          }
        }
        return f
      }
      console.log(minimumDeletions('aababbab'))
    </script>
  </body>
</html>
